package com.content.scaffold.common.exception;

import com.content.scaffold.common.web.ResponseCode;
import com.content.scaffold.common.web.ResponseCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 基类异常
 *
 * @author xiaojl
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseException extends RuntimeException {


    Integer code;
    String message;

    public BaseException() {
        this(ResponseCodeEnum.ERROR);
    }

    public BaseException(String message) {
        super(message);
        this.code = ResponseCodeEnum.ERROR.getCode();
        this.message = message;

    }

    public BaseException(ResponseCodeEnum responseCodeEnum) {
        super(responseCodeEnum.getMessage());
        this.code = responseCodeEnum.getCode();
        this.message = responseCodeEnum.getMessage();

    }

    public BaseException(ResponseCodeEnum responseCodeEnum, String message) {
        super(responseCodeEnum.getMessage());
        this.code = responseCodeEnum.getCode();
        this.message = message;
    }

    public BaseException(String message, Throwable cause) {
        this(ResponseCodeEnum.ERROR, message, cause);
    }

    public BaseException(ResponseCode respCode, String detailMessage, Throwable cause) {
        super(respCode.getMessage(), cause);
        this.code = respCode.getCode();
        this.message = detailMessage;
    }
}
